package cn.yuhh.api.v1.declare;

import cn.yuhh.api.helper.ApiResponse;
import cn.yuhh.api.helper.IDataToMap;
import cn.yuhh.api.service.AbstractApiService;
import cn.yuhh.core.annotation.NotNull;
import cn.yuhh.core.domain.User;
import cn.yuhh.core.type.Role;
import cn.yuhh.core.type.Status;
import com.magic.spring.mongo.Mongo;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

/**
 * 根据地区查出所有的操作者
 */
@Component("listManagerService1.0")
@NotNull(name = "countyCode")
public class ListManagerService extends AbstractApiService {
    @Override
    public Map service(Map request) {
        User user = Mongo.buildMongo().eq("_id", selfId(request)).findOne(User.class);
        List managerList = Mongo.buildMongo().eq("areaInfo.countyCode", user.getAreaInfo().getCountyCode()).eq("role", Role.HANDLER).eq("status", Status.ACTIVE).limit(10,1).find(User.class);
        return ApiResponse.success(managerList, new IDataToMap<User>() {
            @Override
            public void dataToMap(Map<Object, Object> map, User source) {
                map.put("id", source.getId());
                map.put("name", source.getName());
            }
        });
    }
}
